<template>
  <el-dialog
    :model-value="editVisible"
    title="编辑角色"
    width="800"
    :before-close="beforeClose"
  >
    <el-divider />
    <el-form :model="editData" label-width="auto">
      <el-form-item label="账号：">
        <el-input v-model="editData.username" autocapitalize="off" />
      </el-form-item>
      <el-form-item label="姓名：">
        <el-input v-model="editData.nickname" autocapitalize="off" />
      </el-form-item>
      <el-form-item label="邮箱：">
        <el-input v-model="editData.email" type="email" autocapitalize="off" />
      </el-form-item>
      <el-form-item label="密码：">
        <el-input
          v-model="editData.password"
          type="password"
          autocapitalize="off"
        />
      </el-form-item>
      <el-form-item label="备注：">
        <el-input
          v-model="editData.note"
          type="textarea"
          autocapitalize="off"
        />
      </el-form-item>
      <el-form-item label="是否启用：">
        <el-radio-group v-model="editData.status" class="ml-4">
          <el-radio :value="1">是</el-radio>
          <el-radio :value="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="changeEditManagerRoleDialog(false)">取消</el-button>
        <el-button
          type="primary"
          @click="changeEditManagerRoleDialog(false), confirmModifyRowData()"
        >
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { GetManagerRolesListType } from '#/mms/managerRoleType'
import { ModifyManagerRoleApi } from '@/request/mms/managerRoleApi'
import { reactive, toRefs, watch } from 'vue'

const props = defineProps<{
  editVisible: boolean
  rowData: GetManagerRolesListType
}>()

const { editVisible, rowData } = toRefs(props)

const state = reactive<{ editData: GetManagerRolesListType }>({
  editData: { ...rowData.value },
})

const { editData } = toRefs(state)

watch(rowData, () => {
  editData.value = { ...rowData.value }
  
})

const emits = defineEmits<{
  changeEditManagerRoleDialog: [visible: boolean]
  confirmModifyRowData: [data: GetManagerRolesListType]
}>()

const changeEditManagerRoleDialog = (visible: boolean) => {
  emits('changeEditManagerRoleDialog', visible)
}

const confirmModifyRowData = async () => {
  await ModifyManagerRoleApi(editData.value)
  emits('confirmModifyRowData', editData.value)
}

const beforeClose = (done: Function) => {
  emits('changeEditManagerRoleDialog', false)
  done()
}
</script>

<style lang="less" scoped></style>
